<template>
  <el-dialog title="filter" :visible.sync="visible" :close-on-click-modal="false" :before-close="cancel">
      <el-row style="margin-top:-30px">
        <el-tag v-for="tag in tags"
          :key="tag"
          closable
          effect="plain"
          style="margin-left:10px;margin-top:5px"
          @close="handleClose(tag)">
            {{tag}}
          </el-tag>
        <el-input
          maxlength="10"
          class="input-new-tag"
          v-if="inputVisible"
          v-model="inputValue"
          ref="saveTagInput"
          size="small"
          @keyup.enter.native="handleInputConfirm"
          @blur="handleInputConfirm"
        >
        </el-input>
        <el-button v-else class="button-new-tag" size="small" @click="showInput">+ 新方案</el-button>
      </el-row>
      <el-row>Main</el-row>
    <template #footer>
      <el-button @click="cancel">
        Cancel
      </el-button>
      <el-button type="primary">
        OK
      </el-button>
    </template>
  </el-dialog>
</template>
<script>
export default {
  name: 'FilterDialog',
  data () {
    return {
      tags: ['查询已审核', '查询未审核'],
      inputVisible: false,
      inputValue: ''
    }
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    cancel () {
      this.$emit('update:visible', false)
    },
    handleClose (tag) {
      this.tags.splice(this.tags.indexOf(tag), 1)
    },

    showInput () {
      this.inputVisible = true
      this.$nextTick(_ => {
        this.$refs.saveTagInput.$refs.input.focus()
      })
    },

    handleInputConfirm () {
      let inputValue = this.inputValue
      if (inputValue) {
        this.tags.push(inputValue)
      }
      this.inputVisible = false
      this.inputValue = ''
    }
  }
}
</script>
<style scoped>
.button-new-tag {
  margin-left: 10px;
  height: 32.5px;
  margin-top:6px;
  padding-top: 0;
  padding-bottom: 0;
}
.input-new-tag {
  margin-top:6px;
  width: 90px;
  margin-left: 10px;
  vertical-align: bottom;
}
</style>
